import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.RandomUtil;
import com.bigmodel.contant.AmdbId;
import com.bigmodel.contant.StepId;
import com.bigmodel.contant.SystemName;
import com.bigmodel.contant.VerbName;
import com.bigmodel.entity.QAEntity;
import com.bigmodel.util.ExcelUtil;
import com.bigmodel.util.FtlUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AutoTaskTrainV3 {

    private final static  String OUT_PATH = "D:\\javacode\\bigmodel\\bigmodel\\qa_autotask_v2\\";

    private final static String FREEMARKER_BASE_PATH = "autotask/v2/trainv3/";


    private static List<String> verbList = null;
    private static List<String> systemNameList = null;
    private static List<String> nameList = null;
    private static List<String> stepIdList = null;

    static {
        systemNameList = ListUtil.toList(SystemName.LIST_ARRAY);
        verbList = ListUtil.toList(VerbName.LIST_ARRAY);
        nameList = ListUtil.toList(AmdbId.LIST_ARRAY);
        stepIdList = ListUtil.toList(StepId.LIST_ARRAY);
    }

    public static void main(String[] args) {
        T002();
        T003();
        T004();
        T005();
        T006();
    }


    private static void T002(){
        String code = "T002";
        String category = "";

        List<QAEntity> qaEntityList = new ArrayList<>();
        for (String systemName : systemNameList) {
            for(int x = 1 ; x<=3; x++) {
                Map<String, Object> map = new HashMap<>();
                String faultInfo = systemName + "请求成功率低于100%";
                map.put("faultInfo", faultInfo);
                long random = RandomUtil.randomLong(1, 4);
                List<String> nameList = new ArrayList<>();
                for (int i = 1; i <= random; i++) {
                    nameList.add("实例" + i);
                }
                map.put("nameList", nameList);
                map.put("hasData",RandomUtil.randomLong(0,2)==0?"true":"false");
                map.put("type",x);

                String questionContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/answer.ftl");
                qaEntityList.add(new QAEntity(code, category, questionContent, answerContent));
            }
        }
        ExcelUtil.createExcel(qaEntityList,OUT_PATH+code+".xls");
    }


    private static void T003(){
        String code = "T003";
        String category = "";

        List<QAEntity> qaEntityList = new ArrayList<>();
        for (String systemName : systemNameList) {
            for(int x = 1 ; x<=4; x++) {
                Map<String, Object> map = new HashMap<>();
                String faultInfo = systemName + "请求成功率低于100%";
                map.put("faultInfo", faultInfo);
                map.put("systemName", systemName);
                map.put("stepId", UUID.fastUUID().toString().replaceAll("-", ""));
                map.put("status", RandomUtil.randomLong(0, 2) == 0 ? "error" : "success");
                List<String> nameList = new ArrayList<>();
                for (int i = 1; i <= 2; i++) {
                    nameList.add("实例" + i);
                }
                map.put("nameList", nameList);
                map.put("type",x);

                String questionContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/answer.ftl");
                qaEntityList.add(new QAEntity(code, category, questionContent, answerContent));
            }
        }
        ExcelUtil.createExcel(qaEntityList,OUT_PATH+code+".xls");
    }


    private static void T004(){
        String code = "T004";
        String category = "";

        List<QAEntity> qaEntityList = new ArrayList<>();
        for (String systemName : systemNameList) {
            for(int x = 1 ; x<=3; x++) {
                Map<String, Object> map = new HashMap<>();
                String faultInfo = systemName + "请求成功率低于100%";
                map.put("faultInfo", faultInfo);
                map.put("systemName", systemName);
                map.put("hasData", RandomUtil.randomLong(0, 2) == 0 ? "true" : "false");
                List<String> nameList = new ArrayList<>();
                for (int i = 1; i <= 2; i++) {
                    nameList.add("数据库" + i);
                }
                map.put("nameList", nameList);
                map.put("type",x);

                String questionContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/answer.ftl");
                qaEntityList.add(new QAEntity(code, category, questionContent, answerContent));
            }
        }
        ExcelUtil.createExcel(qaEntityList,OUT_PATH+code+".xls");
    }


    private static void T005(){
        String code = "T005";
        String category = "";

        List<QAEntity> qaEntityList = new ArrayList<>();
        for (String systemName : systemNameList) {
            for(int x = 1 ; x<=4; x++) {
                Map<String, Object> map = new HashMap<>();
                String faultInfo = systemName + "请求成功率低于100%";
                map.put("faultInfo", faultInfo);
                map.put("systemName", systemName);
                map.put("stepId", UUID.fastUUID().toString().replaceAll("-", ""));
                map.put("status", RandomUtil.randomLong(0, 2) == 0 ? "error" : "success");
                List<String> nameList = new ArrayList<>();
                for (int i = 1; i <= 2; i++) {
                    nameList.add("数据库" + i);
                }
                map.put("nameList", nameList);
                map.put("type",x);

                String questionContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/answer.ftl");
                qaEntityList.add(new QAEntity(code, category, questionContent, answerContent));
            }
        }
        ExcelUtil.createExcel(qaEntityList,OUT_PATH+code+".xls");
    }

    private static void T006(){
        String code = "T006";
        String category = "";

        List<QAEntity> qaEntityList = new ArrayList<>();
        for (String systemName : systemNameList) {
            for(int x = 1 ; x<=2; x++) {
                Map<String, Object> map = new HashMap<>();
                String faultInfo = systemName + "请求成功率低于100%";
                map.put("faultInfo", faultInfo);
                map.put("systemName", systemName);
                map.put("status", RandomUtil.randomLong(0, 2) == 0 ? "error" : "success");
                map.put("type",x);

                String questionContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/answer.ftl");
                qaEntityList.add(new QAEntity(code, category, questionContent, answerContent));
            }
        }
        ExcelUtil.createExcel(qaEntityList,OUT_PATH+code+".xls");
    }



}
